package com.uenpay.im.ui.old.activity.movement;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.aswife.ui.MaskImageView;
import com.qyx.android.message.type.PacketType;
import com.uenpay.im.R;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.QYXUserEntity;

import java.util.ArrayList;

/**
 * @author SL
 * @created 2016-1-22 早上10:53:07
 * @copyRight http://www.qiyunxin.com
 * @function TODO
 */
public class MovementMembersAdapter extends BaseAdapter {

	private LayoutInflater mLayoutInflater;
	private ArrayList<QYXUserEntity> arrayList = new ArrayList<QYXUserEntity>();

	public MovementMembersAdapter(Context _Context, ArrayList<QYXUserEntity> _arrayList) {
		mLayoutInflater = LayoutInflater.from(_Context);
		arrayList = _arrayList;
	}

	public void setData(ArrayList<QYXUserEntity> _arrayList) {
		arrayList = _arrayList;
		notifyDataSetChanged();
	}

	public void addData(ArrayList<QYXUserEntity> _arrayList) {
		arrayList.addAll(_arrayList);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return arrayList == null ? 0 : arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayList == null ? null : arrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		MovementMembersViewHodler viewHodler = null;
		QYXUserEntity mQYXUserEntity = arrayList.get(arg0);
		if (arg1 == null) {
			viewHodler = new MovementMembersViewHodler();
			arg1 = mLayoutInflater
					.inflate(R.layout.item_movement_members_layout, arg2,false);
			viewHodler.avatar = (MaskImageView) arg1
					.findViewById(R.id.avatar_iv);
			viewHodler.name = (TextView) arg1.findViewById(R.id.name_tv);
			viewHodler.grade = (TextView) arg1.findViewById(R.id.grade_tv);
			viewHodler.sex = (ImageView) arg1.findViewById(R.id.sex_iv);
			arg1.setTag(viewHodler);
		} else {
			viewHodler = (MovementMembersViewHodler) arg1.getTag();
		}
		viewHodler.name.setText(mQYXUserEntity.nickname);
		if (mQYXUserEntity.sex == 0) {
			viewHodler.sex.setImageResource(R.drawable.icon_woman);
		} else {
			viewHodler.sex.setImageResource(R.drawable.icon_man);
		}
		viewHodler.avatar.SetUrl(APIConfiguration.getAvatarUrlNormal(
				mQYXUserEntity.custid, PacketType.PERSONAL));
		// TODO
		return arg1;
	}
	
	public class MovementMembersViewHodler {

		public MaskImageView avatar;
		public TextView name;
		public TextView grade;
		public ImageView sex;
		public Button agreeBtn;
		public TextView area;
	}


}
